import 'package:flutter/material.dart';
import 'package:flutter_mwm/widget/widget.dart';

class TextViewHorizontalDrawable extends StatelessWidget {
  final String data;
  final double textSize;
  final TextAlign textAlign;
  final Color background;
  final Color highlightBackground;
  final Color textColor;
  final Color highlightTextColor;

  final EdgeInsetsGeometry padding;
  final EdgeInsetsGeometry margin;
  final VoidCallback onPressed;
  final FontWeight fontWeight;

  TextViewHorizontalDrawable(
      this.data, {
        @required this.onPressed,
        this.padding,
        this.background,
        this.highlightBackground,
        this.textColor,
        this.highlightTextColor,
        this.margin,
        this.textSize,
        this.textAlign,
        this.fontWeight,
      });

  @override
  Widget build(BuildContext context) {
    return ClickLayout(
        child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              Expanded(
                  flex: 1,
                  child: TextView(data,
                      textAlign:
                      null == textAlign ? TextAlign.center : textAlign,
                      textColor: textColor,
                      textSize: textSize,
                      fontWeight: fontWeight)),
              Icon(Icons.keyboard_arrow_right, color: Colors.grey)
            ]),
        padding: padding,
        margin: margin,
        onPressed: onPressed,
        background: background,
        highlightBackground: highlightBackground,
        decoration: null);
  }
}

class TextViewTransBackground extends ClickLayout {
  final String data;
  final double textSize;
  final TextAlign textAlign;
  final Color textColor;
  final Color highlightTextColor;
  final EdgeInsetsGeometry padding;
  final EdgeInsetsGeometry margin;
  final VoidCallback onPressed;
  final FontWeight fontWeight;

  TextViewTransBackground(
      this.data, {
        Key key,
        @required this.onPressed,
        this.padding,
        this.textColor,
        this.highlightTextColor,
        this.margin,
        this.fontWeight,
        this.textSize,
        this.textAlign,
      });

  @override
  State<StatefulWidget> createState() {
    return _TextViewTransBackgroundState();
  }
}

class _TextViewTransBackgroundState extends State<TextViewTransBackground> {
  Color textColor;
  bool pressed = false;

  void updateColor() {
    setState(() {
      textColor = pressed ? widget.highlightTextColor : widget.textColor;
    });
  }

  @override
  void initState() {
    super.initState();
    updateColor();
  }

  @override
  Widget build(BuildContext context) {
    return ClickLayout(
      child: Text(
        widget.data,
        textAlign:
        null == widget.textAlign ? TextAlign.center : widget.textAlign,
        style: TextStyle(
            color: textColor,
            fontSize: widget.textSize,
            fontWeight: widget.fontWeight,
            backgroundColor: Colors.transparent),
      ),
      padding: widget.padding,
      margin: widget.margin,
      onPressed: widget.onPressed,
      onHighlightChanged: (bool changed) {
        this.pressed = changed;
        updateColor();
      },
      background: Colors.transparent,
      decoration: null,
    );
  }
}

class TextView extends StatefulWidget {
  final String data;
  final double textSize;
  final double width;
  final double height;
  final TextAlign textAlign;
  final Color background;
  final Color highlightBackground;
  final Color textColor;
  final Color highlightTextColor;
  final EdgeInsetsGeometry padding;
  final EdgeInsetsGeometry margin;
  final VoidCallback onPressed;
  final FontWeight fontWeight;
  final Decoration decoration;
  final AlignmentGeometry alignment;

  TextView(
      this.data, {
        Key key,
        this.width,
        this.height,
        this.onPressed,
        this.padding,
        this.background,
        this.highlightBackground,
        this.textColor,
        this.highlightTextColor,
        this.margin,
        this.fontWeight,
        this.textSize,
        this.textAlign,
        this.alignment,
        this.decoration,
      });

  @override
  State<StatefulWidget> createState() {
    return _TextView();
  }
}

class _TextView extends State<TextView> {
  Color textColor;
  Color background;
  bool pressed = false;

  void updateColor() {
    setState(() {
      textColor = pressed ? widget.highlightTextColor : widget.textColor;
      background = pressed ? widget.highlightBackground : widget.background;
    });
  }

  @override
  void initState() {
    super.initState();
    updateColor();
  }

  @override
  Widget build(BuildContext context) {
    return ClickLayout(
      width: widget.width,
      height: widget.height,
      child: Text(
        widget.data,
        textAlign:
        null == widget.textAlign ? TextAlign.center : widget.textAlign,
        style: TextStyle(
            color: textColor,
            fontSize: widget.textSize,
            fontWeight: widget.fontWeight,
            backgroundColor: Colors.transparent),
      ),
      padding: widget.padding,
      margin: widget.margin,
      onPressed: widget.onPressed,
      onHighlightChanged: (bool changed) {
        this.pressed = changed;
        updateColor();
      },
      alignment: widget.alignment,
      background: background,
      decoration: widget.decoration,
    );
  }
}
